
import 'package:flutterlib/common/config/config.dart';
import 'package:flutterlib/model/post/comment_bean.dart';
import 'package:flutterlib/model/post/comment_bean_tree.dart';
import 'package:flutterlib/model/post/comment_request.dart';
import 'package:flutterlib/model/post/like_bean.dart';
import 'package:flutterlib/model/post/post_bean_page.dart';
import 'package:flutterlib/model/post/post_create_bean.dart';
import 'package:flutterlib/model/post/post_detail_bean.dart';
import 'package:retrofit/retrofit.dart';
import 'package:dio/dio.dart' hide Headers;

import '../api.dart';

part 'post_api.g.dart';

@RestApi()
abstract class PostApi {
  factory PostApi(Dio dio, {String baseUrl}) = _PostApi;

  factory PostApi.builder()=> PostApi(HttpManager().getDio());



  @GET("/post/content/posts/{id}")
  Future<PostDetailBean> getPost(@Path("id") int id);

  @DELETE("/post/admin/posts/{id}")
  Future<void> deletePost(@Path("id") int id);

  //传uid和status可以查询用户的文章不传status查全部，传interestid查询兴趣下文章
  @GET("/post/content/posts")
  Future<PostBeanPage> pageByQuery(@Query("page") int page,
      @Query("size") int size,
      @Query("order") String order,
      @Query("uid") int uid,
      @Query("interestId") int interestId,
      @Query("status") String status,
      );
  @GET("/post/content/posts/collect")
  Future<PostBeanPage> pageByCollect(@Query("page") int page,
      @Query("size") int size,
      @Query("order") String order,
      );

  @POST("/post/content/posts/search")
  Future<PostBeanPage> searchByQuery(@Query("page") int page,
      @Query("size") int size,
      @Query("order") String order,
      @Query("keyword") String keyword
      );

  @GET("/post/content/posts/user")
  Future<PostBeanPage> pageByUserQuery(@Query("page") int page,
      @Query("size") int size,
      @Query("order") String order,
      @Query("uid") int uid,
      );

  @GET("/post/content/posts/interest")
  Future<PostBeanPage> pageByInterestQuery(@Query("page") int page,
      @Query("size") int size,
      @Query("order") String order,
      @Query("interestId") int interestId,
      );

  @GET("/post/content/reports/user")
  Future<PostBeanPage> reportPageByUser(@Query("page") int page,
      @Query("size") int size,
      @Query("order") String order,
      @Query("uid") int uid,
      );

  @GET("/post/content/reports/admin")
  Future<PostBeanPage> reportPageByAdmin(@Query("page") int page,
      @Query("size") int size,
      @Query("order") String order,
      );

  @POST("/post/admin/posts")
  Future<PostDetailBean> publishPost(@Body() PostCreateBean bean);

  @POST("/post/admin/sheets")
  Future<PostDetailBean> publishSheet(@Body() PostCreateBean bean);

  @POST("/post/content/reports")
  Future<PostDetailBean> publishReport(@Body() PostCreateBean bean);

  @GET("/post/content/sheets/card")
  Future<PostBeanPage> pageByQuerySheet(@Query("page") int page,
      @Query("size") int size,
      @Query("order") String order,
      @Query("interestId") int interestId
      );

  @GET("/post/content/sheets")
  Future<PostBeanPage> pageBySheet(@Query("page") int page,
      @Query("size") int size,
      @Query("order") String order,
      @Query("uid") int uid,
      @Query("interestId") int interestId,
      @Query("status") String status,
      );

  @POST("/post/content/posts/{postId}/likes")
  Future<LikeBean> like(@Path("postId") int postId);

  @POST("/post/content/posts/{postId}/unLikes")
  Future<LikeBean> unLike(@Path("postId") int postId);

  @POST("/post/content/posts/{postId}/increaseVisit")
  Future<void> increaseVisit(@Path("postId") int postId);

  @POST("/post/content/sheets/{sheetId}/likes")
  Future<LikeBean> likeCard(@Path("sheetId") int sheetId);

  @POST("/post/content/sheets/{sheetId}/unLikes")
  Future<LikeBean> unLikeCard(@Path("sheetId") int sheetId);

  @POST("/post/content/posts/{postId}/collect")
  Future<void> collect(@Path("postId") int postId);

  @POST("/post/content/posts/{postId}/unCollect")
  Future<void> unCollect(@Path("postId") int postId);


  @GET("/post/content/posts/{postId}/comments/tree_view")
  Future<CommentBeanTree> commentPageByQuery(@Path("postId") int postId,
      @Query("page") int page,
      @Query("order") String order
      );

  @POST("/post/content/posts/comments")
  Future<CommentBean> comments(@Body() CommentRequest request);

  ////////////管理员相关api

  @PUT("/post/admin/posts/{postId}/status/{status}")
  Future<void> updatePostStatus(@Path("postId") int postId, @Path("status") String status);

  @PUT("/post/admin/sheets/{postId}/{status}")
  Future<void> updateCardStatus(@Path("postId") int postId, @Path("status") String status);

  @GET("/post/admin/posts")
  Future<PostBeanPage> pageByQueryAdmin(@Query("page") int page,
      @Query("size") int size,
      @Query("order") String order
      );

  @GET("/post/admin/sheets")
  Future<PostBeanPage> pageByQuerySheetAdmin(@Query("page") int page,
      @Query("size") int size,
      @Query("order") String order,
      );
}


